C++ ゼロオーバーヘッド原則
ゼロオーバーヘッド原則(Zero Overhead Principle)
C++のゼロオーバーヘッド原則
C++ implementations obey the zero-overhead principle: What you don't use, you don't pay for Stroustrup, 1994. And further: What you do use, you couldn't hand code any better.
C++11で設計目標として出てきた
ゼロオーバーヘッドの原則(Zero Overhead Principal)とは、使わない機能のオーバーヘッドを支払うべきではないという原則である。ある機能があったとして、その機能を使わない場合、その機能をサポートするために必要なオーバーヘッドがもたらされてはならない。C++は伝統的に、この原則を強く意識してきた。Bjarne StroustrupがSimulaを使ってシミュレーターを書いたら、使いもしないGCのオーバーヘッドでプログラムの実行時間の80%が浪費されていたことは、あまりにも有名だ。
ref: 本の虫: 2014-10-pre-Urbanaのレビュー: N4230-N4239
The zero-overhead principle is a C++ design principle that states:
1. You don't pay for what you don't use.
2. What you do use is just as efficient as what you could reasonably write by hand.
In general, this means that no feature should be added to C++ that would impose any overhead, whether in time or space, greater than a programmer would introduce without using the feature.
The only two features in the language that do not follow the zero-overhead principle are runtime type identification and exceptions, and are why most compilers include a switch to turn them off.
ref: Zero-overhead principle - cppreference.com
↓
ゼロオーバーヘッドの原則は、次のようなC++設計原則です。
1. 使用しないものにはコストを支払う必要はありません。
2. 実際に使用するものは、合理的に手書きできるものと同じくらい効率的です。
一般に、これは、時間的または空間的を問わず、プログラマがその機能を使用せずに導入するよりも大きなオーバーヘッドを課すような機能を C++ に追加すべきではないことを意味します。
この言語でゼロオーバーヘッドの原則に従っていない機能は、 ランタイム型識別と例外の2つだけであり、ほとんどのコンパイラーにこれらの機能をオフにするスイッチが含まれているのはこのためです。
実行時型識別(Run-Time Type Identification(RTTI))と例外(exception)だけはゼロオーバーヘッド原則に従わない
実行時型情報(Run-Time Type Information)の場合もある
ゼロオーバーヘッド原則への言及がある、例外のゼロオーバーヘッド原則の違反についてのドラフト
N4049: 0 overhead principle violations in exception handling
N4234: 0-overhead-principle violations in exception handling - part 2
C++のゼロオーバーヘッド原則を実現するためにコンパイラが使用しない機能をオフにするフラグが実装されている
GCC:
例外: -fno-exceptions
関連
ゼロコスト抽象化
Rust ゼロコスト抽象化
コルーチン
実行時型情報(RTTI)
dynamic_cast
static_cast
確認用
Q. C++のゼロオーバーヘッド原則とは
Q. ゼロオーバーヘッド原則に従っていない機能は何か
Q. ゼロオーバーヘッド原則に従っている機能は何か
参考
本の虫: 2014-10-pre-Urbanaのレビュー: N4230-N4239
実行時型情報 - Wikipedia
baderouaich/the-zero-overhead-principle: Little demonstration of the Zero Overhead principle.
メモ
Run-time type information - Wikipedia
【プログラミング言語C++ by Bjarne Stroustrup】第1章 はじめに - 緑茶思考ブログ
Big Picture Issues, C++ FAQ
調査用
Google.icon C++ ゼロオーバーヘッド原則(日)
Google.icon C++ Zero Overhead Principle(英)
Wikipedia.icon
C++ ゼロオーバーヘッド原則 - Wikipedia(日)
C++ ゼロオーバーヘッド原則(検索) - Wikipedia(日)
Wikipedia.icon
C++ Zero Overhead Principle - Wikipedia(英)
C++ Zero Overhead Principle(検索) - Wikipedia(英)
#C/C++